package mk.com.ldm.corepoint.administration.server;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class AppDB {
	private static AppDB db = null;
	private static Connection conn = null;
	public static String connectionString = "jdbc:postgresql:corepoint";
//	protected AppDB(){
//		getConnection();
//	}
	
	public String getConnectionString(){
		return connectionString;
	}
	
	public static ResultSet execSql(String sql) {
		Statement s = null;
		ResultSet rs = null;
		try {
			s = conn.createStatement();
			rs = s.executeQuery(sql);
		} catch (SQLException e) {
			return null;
		}
		return rs;
	}
	
	public static Statement insertSql(String sql){
		Statement s = null;
		try {
			s = conn.createStatement();
			s.executeUpdate(sql);
		} catch (SQLException e) {
			return null;
		}
		return s;
	}
	
	public static AppDB getInstance(){
		if(db==null)
			db = new AppDB();
		return db;
	}
	
	public static Connection getConnection(String connectionString){
		try{
			Class.forName("org.postgresql.Driver");
			conn = DriverManager.getConnection(connectionString, "postgres", "localpass");
		}catch(Exception e){
			e.printStackTrace();
		}
		return conn;
	}
	
}
